package com.qys.livesMall.anchor.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.anchor.business.LiveRoomGiftBusiness;
import com.qys.livesMall.anchor.model.dto.lives.app.ExchangeGoldDTO;
import com.qys.livesMall.anchor.model.dto.lives.app.GiveGiftDTO;
import com.qys.livesMall.anchor.model.dto.task.SellTaskBasePageDTO;
import com.qys.livesMall.anchor.model.vo.lives.app.AppLivesGiftListVO;
import com.qys.livesMall.anchor.model.vo.lives.app.GiftListVO;
import com.qys.livesMall.anchor.model.vo.lives.app.UserBalanceVO;
import com.qys.livesMall.anchor.service.AnchorLivesGiftService;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 直播礼物表 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-06-21
 */
@RestController
@Tag(name = "APP-主播直播礼物")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/app/anchor/lives/gift")
public class AppAnchorLivesGiftController {


    private final AnchorLivesGiftService livesGiftService;
    private final LiveRoomGiftBusiness liveRoomGiftBusiness;


    @PostMapping("/pageByApp")
    @Operation(summary = "分页查询直播礼物列表")
    public R<Page<AppLivesGiftListVO>> pageByApp(@RequestBody SellTaskBasePageDTO queryDTO) {
        return R.ok(livesGiftService.pageByApp(queryDTO));
    }
    @PostMapping("/giveGift")
    @Operation(summary = "赠送礼物")
    public R<Void> giveGift(@RequestBody @Validated GiveGiftDTO giveDTO) {
        liveRoomGiftBusiness.giveGift(giveDTO, null);
        return R.ok();
    }
    @PostMapping("/listGift/{livesRoomNum}/{livesSessionId}")
    @Operation(summary = "直播间用户榜单(根据礼物)", parameters =
            {@Parameter(name = "livesRoomNum", description = "直播间编号"),
                    @Parameter(name = "livesSessionId", description = "主播直播场次编号")})
    public R<List<GiftListVO>> listGift(@PathVariable String livesRoomNum, @PathVariable Long livesSessionId) {
        return R.ok(liveRoomGiftBusiness.listGift(livesRoomNum,livesSessionId));
    }
    @GetMapping("/exchangeGold")
    @Operation(summary = "金币余额")
    public R<UserBalanceVO> goldBalance() {
        return R.ok(liveRoomGiftBusiness.goldBalance());
    }

    @GetMapping("/exchangeGoldRatio")
    @Operation(summary = "余额兑换金币比例")
    public R<BigDecimal> exchangeGoldRatio() {
        return R.ok(liveRoomGiftBusiness.exchangeGoldRatio());
    }

    @PostMapping("/exchangeGold")
    @Operation(summary = "兑换金币")
    public R<Void> exchangeGold(@RequestBody @Validated ExchangeGoldDTO exchangeGoldDTO) {
        exchangeGoldDTO.setUserId(SecurityUtils.getUserId());
        liveRoomGiftBusiness.exchangeGold(exchangeGoldDTO);
        return R.ok();
    }
}
